package com.zg.shop.index;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.zg.shop.category.Category;
import com.zg.shop.category.CategoryService;
import com.zg.shop.product.Product;
import com.zg.shop.product.ProductService;

public class IndexAction extends ActionSupport{
	
	private CategoryService categoryService;
	private ProductService productService;
	private List<Product> productHots;
	private List<Product> productNews;
	
	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public void setProductService(ProductService productService) {
		this.productService = productService;
	}

	public List<Product> getProductHots() {
		return productHots;
	}
	
	public List<Product> getProductNews() {
		return productNews;
	}

	@Override
	public String execute() throws Exception {
		List<Category> categorys = categoryService.findAll();
		ActionContext.getContext().getSession().put("categorys", categorys);
		
		productHots = productService.findHot();
		productNews = productService.findNew();
		return "indexSuccess";
	}
}
